﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace VectorQuantity
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            String str1 = textBox1.Text.Trim();
            string[] s1 = str1.Split(',');
            
            double x1 = double.Parse(s1[0]);
            double y1 = double.Parse(s1[1]);
            double z1 = double.Parse(s1[2]);

            String str2 = textBox2.Text.Trim();
            String[] s2 = str2.Split(',');
            double x2 = double.Parse(s2[0]);
                double y2 = double.Parse(s2[1]);
                double z2 = double.Parse(s2[2]);
            String str3 = textBox3.Text.Trim();
            String[] s3 = str3.Split(',');
            double x3 = double.Parse(s3[0]);
            double y3 = double.Parse(s3[1]);
            double z3 = double.Parse(s3[2]);
            //设点A坐标为(x1,y1,z1) B(x2,y2,z2) C(x3,y3,z3)
            //则向量AB坐标(x2-x1,y2-y1,z2-z1) AC(x3-x1,y3-y1,z3-z1)
            //若共线
            double a1 = x2 - x1; double a2 = y2 - y1; double a3 = z2 - z1;
            double b1 = x3 - x1; double b2 = y3 - y1; double b3 = z3 - z1;
            double c1 = x3 - x2; double c2 = y3 - y2; double c3 = z3 - z2;
            //(a1 / b1 == a2 / b2 && a1 / b1 == a3 / b3)|| (c1 / b1 == c2 / b2 && c1 / b1 == c3 / b3)  || (c1 / a1 == c2 / a2 && c1 / a1 == c3 / a3)
            
            if ((a1 * b2 == a2 * b1 && a1 * b3 == a3 * b1)
                || (c1 * b2 == c2 * b1  && c1 * b3 == c3 * b1)
                || (c1 * a2 == c2 * a1 && c1 * a3 == c3 * a1)
                ) {
                label7.Text = "三点坐标共线，请重新输入";
            }
            else
            {//两个不平行的向量叉积为法线向量
                double x = a1 * b1;
                double y = a2 * b2;
                double z = a3 * b3;

                String nlv1 = x.ToString() + "," + y.ToString() + "," + z.ToString();
                textBox4.Text = nlv1;
                textBox5.Text= (-x).ToString() + "," +(- y).ToString() + "," +(- z).ToString();

            }

             
        }

        private void label7_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(e.KeyChar == 8 || (e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == 44 || e.KeyChar == 46))
            {
                e.Handled = true;
            }
        }

        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(e.KeyChar == 8 || (e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == 44 || e.KeyChar == 46))
            {
                e.Handled = true;
            }
        }

        private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(e.KeyChar == 8 || (e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == 44 || e.KeyChar == 46))
            {
                e.Handled = true;
            }
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
